package com.gxa.modules.service.lx.impl;

import com.gxa.common.constant.PageInfo;
import com.gxa.common.vo.R2;
import com.gxa.modules.mapper.lx.HomeMapper;
import com.gxa.modules.mapper.lx.OrderManageMapper;
import com.gxa.modules.service.lx.HomeService;
import com.gxa.modules.service.lx.OrderManageService;
import com.gxa.modules.utils.DateUtils;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class HomeServiceImpl implements HomeService {

    @Autowired(required = false)
    private HomeMapper homeMapper  ;


    @Override
    public R2 queryHomeInfo(Map map) {

        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -0);
        String today1 = new SimpleDateFormat( "yyyy-MM-dd 00:00:00").format(cal.getTime());
        String today2 = new SimpleDateFormat( "yyyy-MM-dd 23:59:59").format(cal.getTime());
        cal.add(Calendar.DATE, -1);
        String yesterday1 = new SimpleDateFormat( "yyyy-MM-dd 00:00:00").format(cal.getTime());
        String yesterday2 = new SimpleDateFormat( "yyyy-MM-dd 23:59:59").format(cal.getTime());

        map.put("date1",today1);
        map.put("date2",today2);
        Integer todayvisitor = homeMapper.countVisitor(map);
        Integer todayorders = homeMapper.countOrder(map);
        Double  todayearning = homeMapper.countEarning(map);

        map.put("date1",yesterday1);
        map.put("date2",yesterday2);
        Integer yesterdayvisitor = homeMapper.countVisitor(map);
        Integer yesterdayorders = homeMapper.countOrder(map);
        Double  yesterdayearning = homeMapper.countEarning(map);

        Integer sumvisitor = homeMapper.sumVisitor(map);
        Integer sumdayorders = homeMapper.sumOrder(map);
        Double  sumearning = homeMapper.sumEarning(map);

        Map map1 = homeMapper.queryShopInfo(map);

        Integer saleGoods = homeMapper.sumGoods(map);

        Integer noDeliver = homeMapper.noDeliver(map);

        Integer activist = homeMapper.activist(map);

        List<Map> goodsList = homeMapper.sortGoods(map);

        List list1 = new ArrayList();
        list1.add(todayvisitor);
        list1.add(yesterdayvisitor);
        list1.add(sumvisitor);

        List list2 = new ArrayList();
        list2.add(todayorders);
        list2.add(yesterdayorders);
        list2.add(sumdayorders);

        List list3 = new ArrayList();
        list3.add(todayearning);
        list3.add(yesterdayearning);
        list3.add(sumearning);

        Map infoMap = new HashMap();
        infoMap.put("visitor",list1);
        infoMap.put("orders",list2);
        infoMap.put("earnings",list3);
        infoMap.put("shopInfo",map1);
        infoMap.put("saleGoods",saleGoods);
        infoMap.put("noDeliver",noDeliver);
        infoMap.put("activist",activist);
        infoMap.put("goodsList",goodsList);



        R2 r2 = new R2();
        r2.setCode(200);
        r2.setMsg("查询成功");
        r2.setData(infoMap);


        return r2;
    }
}
